
<template>
  <div>
  <el-dialog title="更新信息" :visible="true">
    <el-form :model="handlefrom" :rules="rules" ref="rulesForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="车牌"  prop="plateNum">
        <el-input v-model="handlefrom.plateNum" autocomplete="off" ></el-input>
      </el-form-item>

      <el-form-item label="颜色"  prop="color">
        <el-input v-model="handlefrom.color" autocomplete="off" ></el-input>
      </el-form-item>

      <el-form-item label="品牌"  prop="brand">
        <el-input v-model="handlefrom.brand" autocomplete="off" ></el-input>
      </el-form-item>

      <el-form-item label="车主电话"  prop="phone">
        <el-input v-model="handlefrom.phone" autocomplete="off" ></el-input>
      </el-form-item>

      停车类型（0常驻，1临时）
      <el-radio v-model="handlefrom.tempCar" :label="1">否</el-radio>
      <el-radio v-model="handlefrom.tempCar" :label="0">是</el-radio>

      <el-form-item label="备注"  prop="remark">
        <el-input v-model="handlefrom.remark" autocomplete="off" ></el-input>
      </el-form-item>

      <div class="block">
        <span class="demonstration">时间</span>
        <el-date-picker
            v-model="handlefrom.endTime"
            type="date"
            placeholder="选择日期">
        </el-date-picker>
      </div>

    是否离开
    <el-radio v-model="handlefrom.leave" :label="1">否</el-radio>
    <el-radio v-model="handlefrom.leave" :label="0">是</el-radio>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="reset" type="primary" >取 消</el-button>
      <el-button @click="submit" type="primary" >确 定</el-button>
    </div>
  </el-dialog>
  </div>
</template>
<script>
export default {
  name: "handleUpdate",
  computed:{
  },
  data(){
    return {
      handlefrom:{
        plateNum:'',
        color:'',
        brand:'',
        phone:'',
        tempCar:'',
        remark:'',
        endTime:'',
        leave:'',
      },
      rules:{
        phone:[
          { required:true ,message:"请输入手机号" ,trigger:"blur" },
          {
            validat:(rule, value, callback) => {
              let aaa = /^1[3-9]\\d{9}$\n/
              if (!aaa.test(value)) {
                callback(new Error("手机号不合规"));
              }else {
                callback()
              }
            },trigger: "blur",
          }
        ],
        color:[
          { required : true , message:"请输入颜色", trigger:"blur" },
        ],
        brand:[
          { required:true , message:"请输入型号", trigger:"blur" },
        ]
      }
    }
  },
  created(){
    let id = this.$route.query.id;
    if(id){
      this.getQuestion(id)
    }

  },
  methods:{
    submit(){
      this. axios.post("car/handleupdate",this.handlefrom).then((response) => {
        this.$router.push("/admin/car")
      })

    },
    reset(){
      this.$router.push("/admin/car")
    },
  getQuestion(id){
    this.axios.get("car/"+id).then(response => {
      if(response.data.car.phone==true){
        response.data.car.phone=1
      }else if(response.data.car.phone==false){
        response.data.car.phone=0
      }else if(response.data.car.leave==true){
        response.data.car.leave=1
      }else if (response.data.car.leave==false){
        response.data.car.leave=0
      }

      if(response.data.car.tempCar==true){
        response.data.car.tempCar=1
      }else if (response.data.car.tempCar==false){
        response.data.car.tempCar=0
      }
      this.handlefrom = response.data.car;
    })
    }
  }
}
</script>

<style>

</style>